#include "time_dispaly.h"


// 时间显示相关对象
lv_obj_t *time_label = NULL;
lv_obj_t *date_label = NULL;  // 日期显示标签
lv_obj_t *week_label = NULL;  // 星期显示标签

LV_FONT_DECLARE(lv_font_fan_24);  //


// 更新时间、日期和星期显示
void update_time(void)
{
    if(time_label == NULL || date_label == NULL || week_label == NULL) return;
    
    time_t now;
    struct tm *timeinfo;
    time(&now);
    timeinfo = localtime(&now);
    
    // 1. 时间（时:分:秒，突出显示）
    char time_str[20];
    strftime(time_str, sizeof(time_str), "%H:%M:%S", timeinfo);
    lv_label_set_text(time_label, time_str);
    
    // 2. 日期（年-月-日，辅助信息）
    char date_str[20];
    strftime(date_str, sizeof(date_str), "%Y-%m-%d", timeinfo);
    lv_label_set_text(date_label, date_str);
    
    // 3. 星期（中文，辅助信息）
    const char *weekdays[] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
    lv_label_set_text(week_label, weekdays[timeinfo->tm_wday]);
}

// 定时器回调（每秒更新）
void timer_callback(lv_timer_t *timer)
{
    update_time();
}

// 初始化时间模块
void create_time_on_ui_screen1(void)
{
    //创建---用于存放标签的容器
    lv_obj_t *main_cont = lv_obj_create(ui_Screen4);
    lv_obj_set_style_bg_color(main_cont, lv_color_hex(0x222222), 0);  
    lv_obj_set_style_bg_opa(main_cont, 150, 0);  // 透明度200
    lv_obj_set_style_radius(main_cont, 8, 0);    // 圆角
    lv_obj_set_size(main_cont, 220, 120);        
    lv_obj_set_pos(main_cont,300, 480);  
    lv_obj_set_flex_flow(main_cont, LV_FLEX_FLOW_COLUMN);
    lv_obj_set_flex_align(main_cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    lv_obj_set_style_pad_ver(main_cont, 8, 0);  

    //日期标签
    date_label = lv_label_create(main_cont);
    lv_obj_set_style_text_font(date_label, &lv_font_fan_24, 0);  
    lv_obj_set_style_text_color(date_label, lv_color_hex(0xCCCCCC), 0);  

    // 时间标签
    time_label = lv_label_create(main_cont);
    lv_obj_set_style_text_font(time_label, &lv_font_fan_24, 0);  // 大字体，突出核心
    lv_obj_set_style_text_color(time_label, lv_color_hex(0xFFFFFF), 0);  // 白色，醒目

    //星期标签
    week_label = lv_label_create(main_cont);
    lv_obj_set_style_text_font(week_label, &lv_font_fan_24, 0);  // 小字体，与日期呼应
    lv_obj_set_style_text_color(week_label, lv_color_hex(0xCCCCCC), 0);  // 浅灰色，统一辅助色

    //初始化显示
    update_time(); 
    lv_timer_create(timer_callback, 1000, NULL);  // 每秒更新一次时间
}